package com.purong.purong.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;

import com.purong.purong.R;
import com.purong.purong.bean.PeriodBean;
import com.purong.purong.util.CommonUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/22.
 */
public class PeriodDialog extends Dialog {
    private Context mContext;
    private OnRefundReasonListener mListener;
    private List<PeriodBean> reasonList=new ArrayList<>();
    private PeriodBean selectReason;
    public PeriodDialog(Context context, List<PeriodBean> dataList, OnRefundReasonListener listener) {
        super(context, R.style.DialogTransparent);
        this.mContext=context;
        if (dataList!=null)
        this.reasonList =dataList;
        this.mListener=listener;
        setCanceledOnTouchOutside(false);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.dialogWindowAnim);

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_loan_period);
        findViewById(R.id.main_lay).setLayoutParams(new FrameLayout.LayoutParams(CommonUtil.getScreenWidth(mContext), ViewGroup.LayoutParams.WRAP_CONTENT));
        if (reasonList.size()!=0);
        selectReason=reasonList.get(0);
        PeriodPickerScrollView reasonPick = (PeriodPickerScrollView)findViewById(R.id.reason);
        reasonPick.setData(reasonList);
        reasonPick.setSelected(0);

        reasonPick.setOnSelectListener(new PeriodPickerScrollView.onSelectListener() {
            @Override
            public void onSelect(PeriodBean resaon) {
                selectReason=resaon;
            }
        });
        findViewById(R.id.btnCancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (mListener!=null){
                    mListener.onCancel();
                }
                dismiss();
            }
        });
        findViewById(R.id.btnSubmit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener!=null){
                    mListener.onSelect(selectReason);
                }
                dismiss();
            }
        });

    }

    public interface OnRefundReasonListener{
        void onCancel();
        void onSelect(PeriodBean reason);
    }
}
